package com.cn.Api.controller;


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.io.*;


@RestController
public class TestController {


    @RequestMapping("/web/test1")
    public void test1(HttpServletRequest request) {

        request.getSession().setAttribute(request.getSession().getId(),"aaa");
    }

    public static void main(String[] args) {
        String a=" ab ";
        System.out.println(trim(a));
    }
    private static  String trim(String str){
        File file=new File("d://a.txt");
        LineNumberReader lineNumberReader=null;

        if(!file.getParentFile().exists()){
            file.getParentFile().mkdir();
        }
        BufferedInputStream in = null;
        OutputStream out = null;
        try {
            lineNumberReader=new LineNumberReader(new FileReader(file));

            out=new BufferedOutputStream(new FileOutputStream("d://d.txt"));
            String i;
            while ((i= lineNumberReader.readLine())!=null){
                System.out.println(lineNumberReader.getLineNumber()+"str:"+i);
                out.write(i.getBytes());
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try{
                lineNumberReader.close();
                out.close();
            }catch (IOException o){
                System.out.println("错误");
            }

        }

        return null;


}



    @RequestMapping("/web/test2")
    public String test2(HttpServletRequest request) {

        String attribute = request.getSession().getAttribute(request.getSession().getId()).toString();
        System.out.println("wachat:" + attribute);
        return attribute;
    }

}